package zhoufu.sz.sanxiao_check.presents;

import javax.inject.Inject;
import zhoufu.sz.sanxiao_check.models.CheckItemModel;
import zhoufu.sz.sanxiao_check.net.BasicRequestRepository;
import zhoufu.sz.sanxiao_check.net.RequestHelper;
import zhoufu.sz.sanxiao_check.ui.contract.CheckItemContract;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/7/30
 */
public class CheckItemPresenter implements BasePresent
{

    private CheckItemContract.View view;

    private BasicRequestRepository _Repository;

    @Inject
    public CheckItemPresenter(BasicRequestRepository _Repository)
    {
        this._Repository = _Repository;
    }

    public void bindView(CheckItemContract.View view)
    {
        this.view = view;
    }

    @Override public void onStart()
    {
        _Repository.GetLastExamine(view.SID(), new RequestHelper.RequestCallBack<CheckItemModel>()
        {
            @Override public void onPullStart()
            {
                view.vStart();
            }

            @Override public void onPullFailud(Throwable throwable)
            {
                view.pullFaild();
            }

            @Override public void onPullEnd()
            {
                view.pullEnd();
            }

            @Override public void onPullSuccessed(CheckItemModel s)
            {
                view.completedLoadMore();
                if ( s.isSuccess() )
                {
                    if ( s.getData().size() > 0 )
                    {
                        view.setData(s.getData().get(0).getDangers());
                    } else
                    {
                        view.showEmptyView();
                    }
                } else
                {
                    view.pullFaild();
                    view.showMessage(s.getErrMsg());
                }
            }
        });
    }


    @Override public void onPause()
    {

    }

    @Override public void onDestroy()
    {

    }
}
